package com.hunan.api.catv.service.biz.report;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hunan.api.catv.common.ConstantsMsg;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.entity.po.MemberReportRecord;
import com.hunan.api.catv.entity.vo.MemberReportRecordVo;
import com.hunan.api.catv.service.ResultService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author: wangchao
 * @Date: 2020/12/21 14:08
 */
@Service
public class MemberReportRecordBiz extends ResultService {

    /**
     * 新增举报
     */
    public ServiceResult saveReportRecord(Integer memberId, MemberReportRecordVo memberReportRecordVo) {
        //todo:举报类型传值和后台类型不一致更改
        Integer reportType = memberReportRecordVo.getReportType();
        if (reportType == 1) {
            reportType = 2;
        } else if (reportType == 2) {
            reportType = 1;
        }
        memberReportRecordVo.setReportType(reportType);
        MemberReportRecord memberReportRecord1 = new MemberReportRecord().selectOne(new QueryWrapper<MemberReportRecord>()
                .eq(MemberReportRecord.MEMBER_ID, memberId)
                .eq(MemberReportRecord.REPORT_TYPE, reportType)
                .eq(MemberReportRecord.REPORT_ID, memberReportRecordVo.getReportId())
                .eq(memberReportRecordVo.getReportTag() != null, MemberReportRecord.REPORT_TAG, memberReportRecordVo.getReportTag())
                .eq(memberReportRecordVo.getReportDescription() != null, MemberReportRecord.REPORT_DESCRIPTION, memberReportRecordVo.getReportDescription())
        );
        if (memberReportRecord1 != null) {
            return buildOK(true, ConstantsMsg.admin_edit_success);
        }
        MemberReportRecord memberReportRecord = new MemberReportRecord();
        BeanUtils.copyProperties(memberReportRecordVo, memberReportRecord);
        boolean insert = memberReportRecord.setCreateTime(new Date()).setMemberId(memberId).insert();
        return buildOK(insert, ConstantsMsg.admin_edit_success);
    }
}
